/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred.gui.pruefung;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import de.mordred.Frage;
import de.mordred.FragenPreSelector;
import de.mordred.Main;
import de.mordred.gui.FixedPanel;
import de.mordred.gui.TopLeiste;
import de.mordred.gui.VerticalFlowLayout;

public class JahrSelection extends FixedPanel
{
	private static final long serialVersionUID = 8816876466347033189L;
	private ButtonGroup _jahresbuttons;
	private ButtonGroup _tage;

	// 90 sekunden pro frage

	public JahrSelection()
	{
		this.setLayout(new BorderLayout());

		this.add(new TopLeiste(null, "Prüfung", null), BorderLayout.NORTH);

		JPanel center = new JPanel(new VerticalFlowLayout());

		_jahresbuttons = new ButtonGroup();
		for (final int x : Main.getExaminaJahre())
		{
			String abschn = x % 10 <= 5 ? "Frühjahr" : "Herbst";

			String titel = "" + x / 100 + " " + abschn;
			final JRadioButton box = new JRadioButton(titel);
			box.setActionCommand("" + x);
			_jahresbuttons.add(box);
			center.add(box);
		}

		JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		JRadioButton day1 = new JRadioButton("Tag 1");
		day1.setActionCommand("" + 1);
		JRadioButton day2 = new JRadioButton("Tag 2");
		day2.setActionCommand("" + 2);

		_tage = new ButtonGroup();
		_tage.add(day1);
		_tage.add(day2);
		radioPanel.add(day1);
		radioPanel.add(day2);

		center.add(radioPanel);

		JButton start = new JButton("Starten");

		this.add(center, BorderLayout.CENTER);

		JPanel southpanel = new JPanel(new VerticalFlowLayout());

		southpanel.add(new JLabel("90 Sekunden pro Frage"));
		southpanel.add(start);
		this.add(southpanel, BorderLayout.SOUTH);

		start.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e)
			{

				int jahr = Integer.valueOf(_jahresbuttons.getSelection().getActionCommand());
				int tag = Integer.valueOf(_tage.getSelection().getActionCommand());

				ArrayList<Frage> liste = Main.getFragen();
				ArrayList<Integer> jahre = new ArrayList<Integer>();
				jahre.add(jahr);
				liste = FragenPreSelector.getFragenByJahr(liste, jahre);
				liste = FragenPreSelector.getFragenByTag(liste, tag);

				Main.setNextPanel(new PruefungsFrageGui(liste));

			}
		});
	}
}
